<?php 
	$langlist = $this->Session->read("langlist");
	// pr($valute);
	// pr($pagamenti);
	// pr($categorie);die;
?>
<link rel="stylesheet" href="<?php echo $this->webroot;?>css/bootstrap-tagsinput.css"/>
<script type="text/javascript" src="<?php echo $this->webroot;?>js/typeahead.min.js"></script>    
<script type="text/javascript" src="<?php echo $this->webroot;?>js/bootstrap-tagsinput.min.js"></script>    
<div class="row">
    <div class="col-md-8 col-md-offset-2" style="background: #fff; padding-bottom: 50px;">
        <form role="form" name="Bookmaker" method="post" action="<?php echo $this->webroot?>Bookmakers/save/<?php echo $bookmaker["Bookmaker"]["id"] ?>" >
          <input type="hidden" name="BookmakerLang[ita][id]" value="<?php echo $bookmaker["BookmakerLang"]["ita"]["id"]?>" />
          <input type="hidden" name="BookmakerLang[eng][id]" value="<?php echo $bookmaker["BookmakerLang"]["eng"]["id"]?>" />
          <input type="hidden" name="Bookmaker[id]" id="bookmaker_id" value="<?php echo $bookmaker["Bookmaker"]["id"]?>" />
          <br>
		  <div class="row">
	          <div class="form-group  col-md-6">
			      <span class="btn btn-file" style=" position: absolute;width: 200px; height: 100px; z-index: 1000;top:0px;left:0px;cursor: pointer;">
				  	<input type="file" class="fileinput" data-object-id="<?php echo $bookmaker["Bookmaker"]["id"]; ?>" data-img="logo" data-action="<?php echo $this->webroot?>Bookmakers/update_logo" data-attach-tipo="LOGO" style=" width: 100px; height: 100px; cursor: pointer; " >
			      </span>
		          <img class="thumbnail" id="logo" src="<?php echo $this->webroot.$bookmaker["Logo"]["webpath"];?>">
	          </div>
	          <div class="form-group  col-md-6">
			      <span class="btn btn-file" style=" position: absolute;width: 200px; height: 100px; z-index: 1000;top:0px;left:0px;cursor: pointer;">
				  	<input type="file" class="fileinput" data-object-id="<?php echo $bookmaker["Bookmaker"]["id"]; ?>" data-img="logo_slim" data-action="<?php echo $this->webroot?>Bookmakers/update_logo_slim" data-attach-tipo="LOGO_SLIM" style=" width: 100px; height: 20px; cursor: pointer; " >
			      </span>
		          <img class="thumbnail" id="logo_slim" src="<?php echo $this->webroot.$bookmaker["LogoSlim"]["webpath"];?>">
	          </div>
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="nome">Nome:</label>
	            <input type="text" class="form-control" id="nome" name="Bookmaker[nome]" value="<?php echo $bookmaker["Bookmaker"]["nome"];?>" placeholder="Inserisci il nome">
	          </div>
          </div>

		  <div class="row">
	          <div class="col-md-12">
          
	           <!-- Nav tabs -->
	            <ul class="nav nav-tabs">
	              <li class="active"><a href="#ita" data-toggle="tab">Ita</a></li>
	              <li><a href="#eng" data-toggle="tab">Eng</a></li>
	            </ul>
	            <!-- Tab panes -->
	            <div class="tab-content">
	              <div class="tab-pane fade in active" id="ita">
	                 <div class="form-group">
	                    <label for="descrizione">Descrizione italiano:</label>
	                    <textarea rows="10" class="form-control" name="BookmakerLang[ita][descrizione]" ><?php echo html_entity_decode($bookmaker["BookmakerLang"]["ita"]["descrizione"]); ?></textarea>
	                  </div>
	              </div>
	              <div class="tab-pane fade in" id="eng">
	                   <div class="form-group">
	                    <label for="descrizione">Descrizione inglese:</label>
	                    <textarea rows="10" class="form-control" name="BookmakerLang[eng][descrizione]" ><?php echo html_entity_decode($bookmaker["BookmakerLang"]["eng"]["descrizione"]); ?></textarea>
	                  </div>
	              </div>
	            </div>
	            
	          </div>
	      </div>
         
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="link">Link:</label>
	            <input type="text" class="form-control" id="link" name="Bookmaker[link]" value="<?php echo $bookmaker["Bookmaker"]["link"];?>" placeholder="Inserisci il link">
	          </div>
          </div>
	          
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="email">Email:</label>
	            <input type="text" class="form-control" id="email" value="<?php echo $bookmaker["Bookmaker"]["email"];?>"  name="Bookmaker[email]" placeholder="Inserisci l'email">
	          </div>  
          </div>
		  <div class="row">
	          <div class="form-group col-md-6">
	            <label for="bonus"><?php echo __("Telefono"); ?>:</label>
	            <input type="text" class="form-control" id="puntmin" value="<?php echo $bookmaker["Bookmaker"]["telefono"];?>" name="Bookmaker[telefono]" placeholder="Inserisci recapito telefonico">
	          </div>   
	          <div class="form-group col-md-6">
	            <label for="maxbonus"><?php echo __("Fax"); ?>:</label>
	            <input type="text" class="form-control" id="versmin" value="<?php echo $bookmaker["Bookmaker"]["fax"];?>" name="Bookmaker[fax]" placeholder="Inserisci fax" min="0">
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-6">
	            <label for="bonus">Bonus:</label>
	            <input type="text" class="form-control" id="puntmin" value="<?php echo $bookmaker["Bookmaker"]["bonus"];?>" name="Bookmaker[bonus]" placeholder="Inserisci il bonus">
	          </div>   
	          <div class="form-group col-md-6">
	            <label for="maxbonus">Max Importo Bonus:</label>
	            <input type="text" class="form-control" id="versmin" value="<?php echo $bookmaker["Bookmaker"]["max_importo_bonus"];?>" name="Bookmaker[max_importo_bonus]" placeholder="Inserisci il massimo importo bonus" min="0">
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-4">
	            <label for="puntmin">Puntata Minima:</label>
	            <input type="text" class="form-control" id="puntmin" value="<?php echo $bookmaker["Bookmaker"]["puntata_minima"];?>" name="Bookmaker[puntata_minima]" placeholder="Inserisci la puntata minima">
	          </div>   
	          <div class="form-group col-md-4">
	            <label for="versmin">Versamento Minimo:</label>
	            <input type="text" class="form-control" id="versmin" value="<?php echo $bookmaker["Bookmaker"]["versamento_minimo"];?>" name="Bookmaker[versamento_minimo]" placeholder="Inserisci il versamento minimo" min="0">
	          </div>   
	          <div class="form-group col-md-4">
	            <label for="verprelminsmin">Prelievo Minimo:</label>
	            <input type="text" class="form-control" id="prelmin" value="<?php echo $bookmaker["Bookmaker"]["prelievo_minimo"];?>" name="Bookmaker[prelievo_minimo]" placeholder="Inserisci il prelievo minimo  " min="0">
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="categorie">Categorie:</label>
	            <select name="Bookmaker[categoria][]" style="" id="categorie" multiple="multiple">
	                <?php foreach($categorie as $key=>$temp){?>
	                    <option <?php if( in_array($key,explode(",",$bookmaker["Bookmaker"]["categoria"]))) echo "selected='selected'"; ?>  value="<?php echo $key?>" ><?php echo $temp ?></option>
	                <?php }?>
	            </select> 
	          </div> 
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="valuta">Valuta:</label>
	            <select name="Bookmaker[valuta][]" style="" class="" id="valuta" multiple="multiple">
	                <?php foreach($valute as $key=>$temp){?>
	                    <option <?php if( in_array($key,explode(",",$bookmaker["Bookmaker"]["valuta"]))) echo "selected='selected'"; ?>  value="<?php echo $key?>" ><?php echo $temp["code"] ?></option>
	                <?php }?>
	            </select> 
	          </div>
          </div>
		  <div class="row">
	          <div class="form-group col-md-6">
	            <label for="mobile"><?php echo __("Mobile"); ?>:</label>
	            <input type="radio" value="1" <?php echo $bookmaker["Bookmaker"]["mobile"]=="1"?'checked':''; ?> name="Bookmaker[mobile]" > <?php echo __("SI"); ?>
	            <input type="radio" value="0" <?php echo $bookmaker["Bookmaker"]["mobile"]!="1"?'checked':''; ?> name="Bookmaker[mobile]" > <?php echo __("NO"); ?>
	          </div>   
	          <div class="form-group col-md-6">
	            <label for="streaming"><?php echo __("Streaming"); ?>:</label>
	            <input type="radio" value="1" <?php echo $bookmaker["Bookmaker"]["streaming"]=="1"?'checked':''; ?> name="Bookmaker[streaming]" > <?php echo __("SI"); ?>
	            <input type="radio" value="0" <?php echo $bookmaker["Bookmaker"]["streaming"]!="1"?'checked':''; ?> name="Bookmaker[streaming]" > <?php echo __("NO"); ?>
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="valutazione"><?php echo __("Valutazione"); ?>:</label>
	            <input type="text" class="form-control" value="<?php echo $bookmaker["Bookmaker"]["valutazione"];?>"  name="Bookmaker[valutazione]" placeholder="Inserisci una valutazione" min="0" max="5">
	          </div>   
          </div>
          
		  <div class="row">
	          <h3 class="text-center"><?php echo __("Metodo di Pagamento"); ?></h3>
	          <div class="form-group col-md-12">
	            <table class="table table-condensed">
	                 <thead>
	                     <th></th>
	                     <th>Pagamento</th>
	                 </thead>
	                 <?php foreach($bookmaker["Pagamento"] as $pagamento){ ?>
	                      <tr>
	                          <td><?php echo ""; ?></td>
	                          <td><?php echo $pagamento["Metodo"]["CategoryLang"][0]["name"]; ?></td>
	                          <td><a href="<?php echo $this->webroot?>Pagamento/edit/<?php echo $pagamento["id"]; ?>"><i class="fa-edit"></i></a></td>
	                      </tr>
	                 <?php }?>
	                 <tfoot>
	                     <tr class="text-right">
	                         <td colspan="3"><a href="<?php echo $this->webroot?>Pagamento/add/<?php echo $bookmaker["Bookmaker"]["id"] ?>"><i class="fa-plus"></i> Aggiungi</a></td>
	                     </tr>
	                 </tfoot>
	            </table>
	          </div>      
          </div>
          
          
		  <div class="row">
	          <h3 class="text-center"><?php echo __("Link Associati"); ?></h3>
	          <div class="form-group col-md-12">
	            <table class="table table-condensed">
	                 <thead>
	                     <th>LINGUA</th>
	                     <th>LINK</th>
	                 </thead>
	                 <?php foreach($bookmaker["Links"] as $link){ ?>
	                      <tr>
	                          <td><i class="<?php echo "famfamfam-flag-".$langlist[$link["lang_id"]]["code"]; ?>"></i> <?php echo $langlist[$link["lang_id"]]["name"]; ?></td>
	                          <td><?php echo $link["link"] ?></td>
	                          <td><a href="<?php echo $this->webroot?>Link/edit/<?php echo $link["id"]; ?>"><i class="fa-edit"></i></a></td>
	                      </tr>
	                 <?php }?>
	                 <tfoot>
	                     <tr class="text-right">
	                         <td colspan="3"><a href="<?php echo $this->webroot?>Link/add/<?php echo $bookmaker["Bookmaker"]["id"] ?>"><i class="fa-plus"></i> Aggiungi link</a></td>
	                     </tr>
	                 </tfoot>
	            </table>
	            <!-- value="<?php echo $bookmaker["Bookmaker"]["valuta"];?>"  name="Bookmaker[valuta]" placeholder="Associa la valuta"> -->
	          </div>      
          </div>
          
          
            
          <div class="col-md-12" >
              <button type="submit" class="btn btn-primary">Salva</button>
              <a  href="<?php echo $this->webroot?>Bookmakers/index" class="btn">Annulla</a>
              <a href="<?php echo $this->webroot ?>Bookmakers/delete/<?php echo $bookmaker["Bookmaker"]["id"]?>" id="elimina_btn" class="btn btn-danger">Elimina</a>
          </div>
          
        </form>
   </div>
  </div>

  <script>
	
	$(".fileinput").on("change", function(){
        var files = this.files;
        var data = null;
        var path = $(this).data("action");
        var attachTipo = $(this).data("attach-tipo");
        var objectId = $(this).data("object-id");
        var img = $(this).data("img");
        for(var i = 0; i < files.length; i++) {
            data = new FormData();
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function(ev){
            	console.log(ev);
            };
             xhr.onload = function(){
               data = jQuery.parseJSON(this.responseText);
               //console.log(data);
               if (data.success==true) {
                    // console.log(img);
                    oImg = $("#"+img);
                    oImg.data("id",data.filesuploaded[0].id);
                    oImg.attr("src","<?php echo $this->webroot; ?>" + data.filesuploaded[0].thumb_webpath);
               } else if (data.success==false) {
                    setFlash(data.message,data.level);
               }
            };
            xhr.open('POST', path, true);
            data.append(attachTipo, files[i]);
    	    data.append('attachTipo', attachTipo);
    	    data.append('objectId', objectId);
            xhr.send(data);
        }
	});
    
    function format(data) {
        console.log(data);
        return "<img class='banner_thumb' src='<?php echo $this->webroot?>" + data.id + "'/>" + data.text;
    }
    
    $(document).ready(
        function() { 
            $('#valuta').select2({
                placeholder:"Seleziona una Valuta"
            }); 
            $('#pagamento').select2({
                placeholder:"Seleziona una Tipo di Pagamento"
            }); 
            $('#categorie').select2({
                placeholder:"Seleziona una Categoria"
            }); 
        });
      
  </script>